package com.jgj.zxkj.lookandcheckjggroupinfo.record.nocheck;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sa.all_cui.mix_ui.recycler.DataConvert;
import com.sa.all_cui.mix_ui.recycler.MultipleItemEntity;

import java.util.ArrayList;

/**
 * Created by all-cui on 2017/11/1.
 */

public class NoCheckDataConvert extends DataConvert {
    @Override
    public ArrayList<MultipleItemEntity> convert() {

        final JSONArray dataArray = JSON.parseObject(getJsonData()).getJSONArray("data");
        if (dataArray == null) {
            return null;
        }
        final int size = dataArray.size();

        parseItem(dataArray, size);

        return ENTITYS;
    }

    private void parseItem(JSONArray dataArray, int size) {
        for (int i = 0; i < size; i++) {
            JSONObject data = dataArray.getJSONObject(i);
            final String id = data.getString("ID");
            final String routerName = data.getString("DLMC");
            final String handleTime = data.getString("BLSJ");
            final String usage = data.getString("YT");
            final String department = data.getString("SQDW");

            final MultipleItemEntity entitys = MultipleItemEntity.builder()
                    .setField(PageDataType.DEPARTMENT, department)
                    .setField(PageDataType.USAGE, usage)
                    .setField(PageDataType.ROUTER, routerName)
                    .setField(PageDataType.HANDLE_TIME, handleTime)
                    .setField(PageDataType.ID, id)
                    .build();
            ENTITYS.add(entitys);

        }
    }
}
